package org.teamh.connection.json.handler;

import org.teamh.connection.json.event.JsonEventObject;
import org.teamh.game.Start;
import org.teamh.logic.datamodel.*;

public class CreepDescriptionHandler extends JsonMasterHandler {

	public CreepDescriptionHandler(Start start, DatamodelManager manager) {
		super(start, manager);
	}
	
	public boolean handleMsg(JsonEventObject json) {
		
		if (json.getSource().startsWith("CreepDescription")) {
			String ID = json.getSource();
			if (json.getProperty().equals("description")) {
				manager.getCreepDescription(ID).setDescription(json.getNewValue());
				return true;
			} else if (json.getProperty().equals("name")) {
				manager.getCreepDescription(ID).setName(json.getNewValue());
				return true;
			} else if (json.getProperty().equals("price")) {
				manager.getCreepDescription(ID).setPrice(Integer.parseInt(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("bounty")) {
				manager.getCreepDescription(ID).setBounty(Integer.parseInt(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("healthMax")) {
				manager.getCreepDescription(ID).setHealthMax(Integer.parseInt(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("income")) {
				manager.getCreepDescription(ID).setIncome(Integer.parseInt(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("slowImmune")) {
				manager.getCreepDescription(ID).setSlowImmune(Boolean.parseBoolean(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("speedMax")) {
				manager.getCreepDescription(ID).setSpeedMax(Double.parseDouble(json.getNewValue()));
				return true;
			} else if (json.getProperty().equals("type")) {
				manager.getCreepDescription(ID).setType(json.getNewValue());
				return true;
			}
			return false;
		} else {
			return false;
		}
	}
}